const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');

const app = express(); // 创建一个express实例
const config = require('./webpack.config.js'); // 引入webpack配置文件
const compiler = webpack(config); // 根据配置文件创建webpack编译器

// 告诉express使用webpack-dev-middleware和webpack.config.js
// webpack-dev-middleware是一个容器，它将webpack处理后的文件传递给一个服务器
app.use(webpackDevMiddleware(compiler, {
    publicPath: config.output.publicPath
}));


// 将文件serve到port 3000
app.listen(3000, function () {
    console.log('Example app listening on port 3000!\n');
});